<? include 'server_config.php'; 
$sql="
	DELETE FROM ndd_auto_login WHERE expire_date < NOW()
";
$result = mysql_query($sql,$connect);

$sql="
	SELECT user_idx, mail, nickname, verified, type FROM ndd_user WHERE mail='$login_mail' AND pwd=password('$login_pwd');
";

//echo $sql;
$result = mysql_query($sql,$connect);

$row = mysql_fetch_row($result);

if ($row[0]!="" && $auto_login!="")//
{
	$rresult = mysql_query($sql,$connect);

	$cookey = $row[0].":".hash("sha256", $row[1]."znvkd~".$row[2].time(), false);
	$expdate = time() + (7 * 24 * 60 * 60);
	setcookie($cookie_auto_login, $cookey, $expdate);

	$dbkey = hash("sha512", $cookey, false);
	$fmtexpd = date("Y-m-d H:i:s", $expdate);
	$sql = "
		INSERT INTO ndd_auto_login VALUES ( {$row[0]}, '$dbkey', '$fmtexpd' )
	";
	$rresult = mysql_query($sql,$connect);
}

if ($row[0]=="")
{
	$_SESSION['user_idx'] = "";

	?>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type='text/javascript'>
		alert("회원정보가 올바르지 않습니다.");
		location.href='login.php';
	</script>
	<?
}
else
{
	$_SESSION['user_idx'] = $row[0];
	$_SESSION['user_mail'] = $row[1];
	$_SESSION['nickname'] = $row[2];
	$_SESSION['verified'] = $row[3];
	$_SESSION['type'] = $row[4];


	if(false)//$_SESSION['verified']=='N')
	{
?>


	<script type='text/javascript'>
		location.href='register_check.php';
	</script>


<?
	}
	else
	{
?>


	<script type='text/javascript'>
		location.href='ndd_cure.php';
	</script>


<?
	}

}

?>
